package com.example.administrator.zhongyichou.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.example.administrator.zhongyichou.base.BaseActivity;
import com.example.administrator.zhongyichou.Bean.BaseEventBean;
import com.example.administrator.zhongyichou.fragment.HelpedDiseaseFragment;
import com.example.administrator.zhongyichou.fragment.HelpedDreamFragment;
import com.example.administrator.zhongyichou.net.protocol.GsonBaseProtocol;
import com.example.administrator.zhongyichou.view.PagerSlidingTabStrip;
import com.example.administrator.zhongyichou.net.core.HttpLoader;
import com.example.administrator.zhongyichou.view.HeaderView;
import com.example.administrator.zhongyichou.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lichenyu on 2017/11/27.
 * 描述：我帮助过
 */

public class IHelpedActivity extends BaseActivity {
    @BindView(R.id.headerview)
    HeaderView headerview;
    @BindView(R.id.tab)
    PagerSlidingTabStrip tab;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    private HelpedDiseaseFragment helpedDiseaseFragment;
    private HelpedDreamFragment helpedDreamFragment;
    private String[] titles = {"疾病求助", "梦想互助"};

    @Override
    protected void init() {
        ButterKnife.bind(this);
        initHead();
        viewpager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                if (position == 0) {
                    if (helpedDiseaseFragment == null)
                        helpedDiseaseFragment = new HelpedDiseaseFragment();
                    return helpedDiseaseFragment;
                } else {
                    if (helpedDreamFragment == null)
                        helpedDreamFragment = new HelpedDreamFragment();
                    return helpedDreamFragment;
                }
            }

            @Override
            public int getCount() {
                return titles.length;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }
        });
        tab.setViewPager(viewpager);
    }

    private void initHead() {
        headerview.setTitle("我帮助过");
        headerview.bindOnclickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case HeaderView.LEFT:
                        finish();
                        break;
                }
            }
        });
    }

    @Override
    protected void responseData(GsonBaseProtocol mGsonBaseProtocal) {

    }

    @Override
    protected HttpLoader initHttpLoader() {
        return null;
    }

    @Override
    protected int initContentView() {
        return R.layout.i_helped_activity;
    }

    @Override
    public boolean onEventBus(BaseEventBean baseEventBean) {

        return false;
    }
}
